var me; // 相当于onLoad 里的this
var todo;
var currentO = {}; // 记录当前操作对象的信息，格式{}
var inputText; // 记录输入内容

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    actionSheetHidden: true,
    actionSheetItems: ['CET3词汇', 'CET4词汇', 'CET6词汇', '专升本词汇','高职词汇'],
    phone: '19312586189',
    open: false,
    learnDetail: [],

    activeNames: ['1'],

    checked :true,
    checkedlanguage:true
  },

  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getPhoneStatus();
  },

  getPhoneStatus() {
    const _this = this;
    wx.request({
      url: 'http://47.120.31.85:8080/word/getRemindUserStatus?phone=' + _this.data.phone,
      method: "GET",
      success: function(res) {
        _this.setData({
          open: res.data.data.open == 0 ? false : true
        })
      }
    })
  },

  onChangeSwitch({ detail }) {
    // 需要手动对 checked 状态进行更新
    this.setData({ checked: detail });
  },

  onChangelanguage({ detail }) {
    // 需要手动对 checked 状态进行更新
    console.log(detail)
    this.setData({ checkedlanguage: detail });
  },

  onShow: function () {
    const _this = this;
    if (typeof this.getTabBar === 'function' &&  this.getTabBar()) {
      this.getTabBar().setData({
        selected: 3     //这里的数字设置当前页面在tabbar里对应的序列，从0开始
      })
    }

    //获取用户的本地缓存数据，userinfo信息是在用户授权登录时保存的
    var info = wx.getStorageSync("userinfo");
    //当本地缓存的用户名称不为""或者null时，设置userinfo信息
    if(info.nickName != '' && info.nickName != null){
       this.setData({
           userInfo: info,
       })
     }

     wx.request({
      url: 'http://47.120.31.85:8080/word/getLearnDetail?username=' + _this.data.userInfo.nickName,
      method: "GET",
      success: function(res) {
        _this.setData({
          learnDetail: res.data.data
        })
      }
    })
  },
  change: function() {
    const _this = this
    wx.request({
      url: 'http://47.120.31.85:8080/word/updateRemindUser?phone=' + _this.data.phone,
      method: "POST",
      success: function(res) {
        _this.getPhoneStatus();
        console.log('易忘提醒状态')
      }
    })
  },
  /* 
  点击“选择词库”后执行的函数，
  主要是控制选项的“显示”与“隐藏”
  */
  clickThesaurus: function (e) {
    this.setData({
      actionSheetHidden: !this.data.actionSheetHidden
    })
  },
  actionSheetChange: function (e) {
    this.setData({
      actionSheetHidden: !this.data.actionSheetHidden
    })
  },
  bindItemTap: function (e) {
    /* 
    此处用来写选择词库的逻辑,
    选了哪个就把哪个词库的id（序号）传给select,
    把词库名传给title
    */
    console.log("选择的词汇库序号："+e.currentTarget.id)
    
    var select = parseInt(e.currentTarget.id);
    wx.setStorageSync('select', select);
    var title = this.data.actionSheetItems[select]
    wx.setStorageSync('title', title)
    console.log(title)
    
    //点击后隐藏菜单
    this.setData({
      actionSheetHidden: !this.data.actionSheetHidden
    })
  },
  // 跳转到“关于我们”页面
  goWe:function(){
    wx.navigateTo({
      url: '../../pages/we/we',
   })
  },
  goLearnHistory: function() {
    wx.navigateTo({
      url: '../../pages/learnHistory/learnHistory',
    })
  },
  onRegister(){
    this.pageRouter.navigateTo({
      url: '../ciku/ck'
    })
}
})